package com.xuecheng.manage_cms_client.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    //    队列bean名称
    public static final String QUEUE_CMS_POSTPAGE = "queue_cms_postpage";
    //      交换机名称
    public static final String EX_ROUTING_CMS_POSTPAGE = "ex_routing_cms_postpage";
    //      队列名称
    @Value("${xuecheng.mq.queue}")
    private String queue_cms_postpage_name;
    //    路由名称key4
    @Value("${xuecheng.mq.routingKey}")
    private String routingKey;

    //            创建交换机
    @Bean(EX_ROUTING_CMS_POSTPAGE)
    public Exchange getExchange() {
        return ExchangeBuilder.directExchange(EX_ROUTING_CMS_POSTPAGE).durable(true).build();
    }
//    声明队列
    @Bean(QUEUE_CMS_POSTPAGE)
    public Queue getQueue() {
        return new Queue(queue_cms_postpage_name);
    }
//    绑定路由和队列
    @Bean
    public Binding getBinding(@Qualifier(QUEUE_CMS_POSTPAGE) Queue queue,@Qualifier(EX_ROUTING_CMS_POSTPAGE)Exchange exchange){
        Binding binding = BindingBuilder.bind(queue).to(exchange).with(routingKey).noargs();
        return binding;
    }



}
